package com.marvels.approve.credit.controller;

import com.marvels.approve.credit.service.CreditReportService;
import com.marvels.approve.process.dto.LaAttachAtmeTypeViewDTO;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/approve/credit/report/service")
public class ApproveCreditReportController {
	@Autowired
	private CreditReportService creditReportService1;
	
	/**
	 * 获取当前支持的所有类型的附件信息
	 * @param loanId
	 * @return
	 */
	@RequestMapping("getAttachmentsByViewKey")
	@ResponseBody
	public MarvelsResultDTO getAttachmentsByViewKey(@RequestParam("loanId") String loanId){
		List<LaAttachAtmeTypeViewDTO> data = null;
		try {
			data = creditReportService1.getAttachmentsByViewKey(loanId);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), data);
		}  catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error("业务异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),e.getMessage(), e);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error("系统异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e);
		}
	}
}
